{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pandas分箱操作"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 分箱操作就是将连续型数据离散化。\n",
    "- 分箱操作分为等距分箱和等频分箱。 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Pandas</th>\n",
       "      <th>PyTorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>40</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>98</td>\n",
       "      <td>85</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>62</td>\n",
       "      <td>29</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Pandas  PyTorch\n",
       "0      48       3        9\n",
       "1      40      20       60\n",
       "2      98      85       26\n",
       "3      62      29       60\n",
       "4      54      54       31"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = np.random.randint(0, 100, size=(5, 3))\n",
    "df = pd.DataFrame(data=data, columns=['Python', 'Pandas', 'PyTorch'])\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1、等宽分箱"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    48\n",
       "1    40\n",
       "2    98\n",
       "3    62\n",
       "4    54\n",
       "Name: Python, dtype: int32"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.Python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    (39.942, 54.5]\n",
       "1    (39.942, 54.5]\n",
       "2      (83.5, 98.0]\n",
       "3      (54.5, 69.0]\n",
       "4    (39.942, 54.5]\n",
       "Name: Python, dtype: category\n",
       "Categories (4, interval[float64, right]): [(39.942, 54.5] < (54.5, 69.0] < (69.0, 83.5] < (83.5, 98.0]]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.cut(df.Python, bins=4)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python\n",
       "(39.942, 54.5]    3\n",
       "(54.5, 69.0]      1\n",
       "(83.5, 98.0]      1\n",
       "(69.0, 83.5]      0\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: xlabel='Python'>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAIFCAYAAAAA3/2aAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA4sElEQVR4nO3deXhNd+LH8c+9iSxIYo2EBtG0hLREbKEVNSpV7YhOW2MZ0cF04VdTxdOYDsX0iVpGN1uZolVFW1SttdYgxD6WUmqJkgSDhCAiOb8/PL0zGbQu9+Z7E+/X89ynPdu9n9tTycc533OOzbIsSwAAAIbYTQcAAAD3NsoIAAAwijICAACMoowAAACjKCMAAMAoyggAADCKMgIAAIzyNh3gdhQUFOjkyZMKCAiQzWYzHQcAANwGy7J04cIFVa1aVXb7rY9/FIsycvLkSYWFhZmOAQAA7sDx48d133333XJ5sSgjAQEBkq5/mcDAQMNpAADA7cjOzlZYWJjj9/itFIsy8vOpmcDAQMoIAADFzK8NsWAAKwAAMIoyAgAAjKKMAAAAoygjAADAKMoIAAAwijICAACMoowAAACjKCMAAMAoyggAADCKMgIAAIyijAAAAKOcKiMTJ07Uww8/7HhGTGxsrJYuXfqL23zxxReqU6eO/Pz89NBDD2nJkiV3FRgAAJQsTpWR++67TyNHjtS2bdu0detWtW7dWh06dNDevXtvuv7GjRvVuXNn9ezZUzt27FBCQoISEhK0Z88el4QHAADFn82yLOtu3qBChQoaPXq0evbsecOyTp06KScnR4sWLXLMa9asmRo0aKBJkybd9mdkZ2crKChIWVlZPLUXAIBi4nZ/f9/xmJH8/HzNnj1bOTk5io2Nvek6KSkpatOmTaF58fHxSklJ+cX3zs3NVXZ2dqEXA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SgoEB//vOf1aJFC0VFRd1yvdq1a+vjjz/W119/rZkzZ6qgoEDNmzfXTz/9dMttkpOTFRQU5HiFhYXdaUwAAODhbJZlWXey4csvv6ylS5dq/fr1uu+++257u7y8PEVGRqpz584aMWLETdfJzc1Vbm6uYzo7O1thYWHKyspSYGDgncS9KzXfWFzkn+kJjo5sbzoCAKAYy87OVlBQ0K/+/nZqzMjP+vbtq0WLFmndunVOFRFJKlWqlKKjo3Xo0KFbruPr6ytfX987iQYAAIoZp07TWJalvn37av78+Vq9erXCw8Od/sD8/Hzt3r1boaGhTm8LAABKHqeOjPTp00ezZs3S119/rYCAAGVkZEiSgoKC5O/vL0nq3r27qlWrpuTkZEnS8OHD1axZM0VEROj8+fMaPXq0jh07pl69ern4qwAAgOLIqTIyceJESVKrVq0KzZ82bZp69OghSUpLS5Pd/p8DLufOnVPv3r2VkZGh8uXLKyYmRhs3blTdunXvLjkAACgR7ngAa1G63QEw7sIAVgAAnHe7v795Ng0AADCKMgIAAIyijAAAAKMoIwAAwCjKCAAAMIoyAgAAjKKMAAAAoygjAADAKMoIAAAwijICAACMoowAAACjKCMAAMAoyggAADCKMgIAAIyijAAAAKMoIwAAwCjKCAAAMIoyAgAAjKKMAAAAoygjAADAKMoIAAAwijICAACMoowAAACjKCMAAMAoyggAADCKMgIAAIyijAAAAKMoIwAAwCjKCAAAMIoyAgAAjKKMAAAAoygjAADAKMoIAAAwijICAACMoowAAACjKCMAAMAoyggAADCKMgIAAIyijAAAAKMoIwAAwCjKCAAAMIoyAgAAjKKMAAAAoygjAADAKMoIAAAwijICAACMoowAAACjnCojycnJaty4sQICAhQcHKyEhAQdOHDgV7f74osvVKdOHfn5+emhhx7SkiVL7jgwAAAoWZwqI99995369OmjTZs2acWKFcrLy1Pbtm2Vk5Nzy202btyozp07q2fPntqxY4cSEhKUkJCgPXv23HV4AABQ/Nksy7LudOPTp08rODhY3333nVq2bHnTdTp16qScnBwtWrTIMa9Zs2Zq0KCBJk2adFufk52draCgIG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YgBrMRAZGSkvLy/TMVBEJkyYwI3u7iGDBw/WH//4R9MxUETY3zfHmJFiIDk5WVlZWaZjoIh89dVXOnLkiIYMGWI6CorAiRMndPz4cdMxUETY3zfHaRoAAGAUp2k82PTp0zkiAgAo8Tgy4sF8fHy0a9cuRUZGmo4CN1i9erXWr1+v9PR02e121apVS7/97W/1wAMPmI4GF1u0aJFSU1MVHx+vFi1aaPXq1RozZowKCgr0zDPP6E9/+pPpiHCh77//Xps2bVJsbKzq1Kmj/fv367333lNubq66deum1q1bm47ocSgjHqBChQo3nX/+/HkFBgbKbr9+AOvs2bNFGQtucurUKT399NPaunWr7Ha7CgoKFB0drRMnTuj06dPq37+/Ro0aZTomXGTy5Mnq27ev6tevr4MHD2r8+PF65ZVX1KlTJ3l5eemTTz5RcnKy+vXrZzoqXGDZsmXq0KGDypYtq0uXLmn+/Pnq3r276tevr4KCAn333Xf69ttvKST/gwGsHiAvL09xcXF67rnnHPMsy1KvXr00aNAgVatWzWA6uNqrr76qqlWr6ty5c/L19dWAAQOUnZ2trVu3avXq1Xr++edVrVo1fjmVEO+//74mTJig3r17a82aNXryySc1duxYvfLKK5KuPzhx1KhR7O8SYvjw4Ro4cKD+9re/afbs2erSpYtefvllvf3225KkpKQkjRw5kjLyPzgy4gEOHTqkLl26KDIyUuPHj1fZsmUlSaVKldKuXbtUt25dwwnhSkFBQdq4caPq1asnScrJyVH58uV15swZBQYGaubMmfrb3/6m/fv3G04KVyhdurT279+v6tWrS7p++nX79u2KioqSJB09elT16tVTTk6OyZhwkaCgIG3btk0REREqKCiQr6+vUlNTFR0dLUnas2eP2rRp47gTL65jAKsHiIiI0MaNGxUSEqIGDRpow4YNpiPBjXx9fQs9+NButys/P1/Xrl2TJDVv3lxHjx41lA6uVrFiRR07dkySdPLkSV27dk1paWmO5ceOHbvlqVoUT//9oDw/P79CD8sLCAjgwoSb4DSNh/D29tY777yj+Ph4denSRV27duVJvSXUI488oiFDhmjGjBny8fHR4MGDVatWLccvpNOnT6t8+fKGU8JVOnTooJ49eyoxMVELFy5U9+7d9frrr8tut8tms2ngwIFq27at6ZhwkZo1a+rgwYOOh5umpKQ4jopJUlpamkJDQ03F81iUEQ/TunVrbd++Xb1791aZMmW482oJNGbMGLVt21blypWTzWZTmTJl9MUXXziWf//99+rRo4e5gHCpd955R1evXtXs2bPVvHlzffDBB3r//ffVoUMHx3gxHoRZcrz88suOh19KcpyO+9nSpUsZL3ITjBkBDLh06ZI2bNig3NxcNWvWTJUqVTIdCUXsypUrysvLU0BAgOkogHGUEQ+Vl5eno0ePKjg4uND5RgBA8WRZFqffb4EBrB5g1KhRunz5siQpPz9fAwYMUNmyZVWnTh1VqlRJf/zjH5WXl2c4JVzlp59+0pkzZxzT//znP9W1a1c9+uij6tatm1JSUgymgzukp6dryJAhat26tSIjI1WvXj09/fTT+sc//lHokD6Kv9zcXA0YMEAtW7bUO++8I0n629/+prJlyyogIEBdunRRdna24ZSehzLiAZKSknThwgVJ0rhx4/Txxx9r0qRJ2r17t6ZPn67Fixdr3LhxhlPCVX73u99p06ZNkqSvv/5arVq10sWLF9WiRQtdunRJcXFxWrRokeGUcJWtW7cqMjJSS5YsUV5eng4ePKiYmBiVKVPG8Uvr5z//KP6SkpL0+eefq0mTJpoxY4b69OmjKVOmaPLkyZoyZYq2bNmiN99803RMz2PBOJvNZmVmZlqWZVnR0dHW5MmTCy2fOXOmVa9ePRPR4AZlypSxDh8+bFmWZTVt2tQaOXJkoeUffPCBFR0dbSIa3KBFixbWW2+95Zj+9NNPraZNm1qWZVlnz561GjRoYL366qum4sHFwsLCrBUrVliWZVk//vijZbfbrQULFjiWf/vtt1aNGjUMpfNcHBnxED+fR0xLS1Pz5s0LLWvevLmOHDliIhbcwNvb2/E34SNHjqhdu3aFlrdr104HDhwwEQ1usH37dv3hD39wTHfp0kXbt29XZmamypcvr1GjRunLL780mBCudObMGT344IOSpFq1asnLy0sRERGO5Q888IBOnz5tKp7Hoox4iClTpuj999+Xj4/PDc+guXDhgnx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QsWON4jLy9PkyZNUqNGjdSwYUP17dvX8R4APB9lBMBtW7RokcqWLSs/Pz+1a9dOnTp10ltvvaUmTZqoXr16mjFjhiRp5syZqlGjhlq2bPmr71mvXj15eXk5pkNDQ3Xq1ClJ0vfffy9vb281bdrUsbxixYqqXbu2vv/+e8e80qVL6/7777/pewDwfJQRALftscce086dO3Xw4EFdvnxZM2bMUJkyZSRJvXr1cpxemTZtml544QXZbLZffc9SpUoVmrbZbCooKHAq183eg2eAAsUHZQTAbStTpowiIiJUvXp1eXsXvhivW7duOnbsmN5//33t27dPiYmJjmU+Pj6SpPz8fKc+LzIyUteuXdPmzZsd8/7973/rwIEDqlu37l18EwCehDICwCXKly+vZ555RgMHDlTbtm113333OZYFBwfL399fy5YtU2ZmprKysm7rPR944AF16NBBvXv31vr167Vr1y5169ZN1apVU4cOHdz1VQAUMcoIAJfp2bOnrl696hi4+jNvb2+9//77mjx5sqpWrepUkZg2bZpiYmL01FNPKTY2VpZlacmSJTecmgFQfNksTqwCcJFPP/1Ur732mk6ePOk4NQMAv4Y7sAK4a5cuXVJ6erpGjhypF198kSICwCmcpgFw10aNGqU6deooJCSEW8MDcBqnaQAAgFEcGQEAAEZRRgAAgFGUEQAAYBRlBAAAGEUZAQAARlFGAACAUZQRAABgFGUEAAAY9f9F18nwcfpRbAAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "s.value_counts().plot.bar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    C\n",
       "1    C\n",
       "2    A\n",
       "3    B\n",
       "4    C\n",
       "Name: Python, dtype: category\n",
       "Categories (4, object): ['D' < 'C' < 'B' < 'A']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.cut(\n",
    "    df.Python,   # 分箱数据\n",
    "    bins=[0, 30, 60, 80, 100],  # 分箱断点\n",
    "    right=False,  # 左闭右开，默认是左开右闭\n",
    "    labels=['D', 'C', 'B', 'A']  # 分箱后分类的标签\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2、等频分箱"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    D\n",
       "1    D\n",
       "2    A\n",
       "3    B\n",
       "4    C\n",
       "Name: Python, dtype: category\n",
       "Categories (4, object): ['D' < 'C' < 'B' < 'A']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.qcut(\n",
    "    df.Python,   # 分箱数据\n",
    "    q=4,  # 4等份\n",
    "    labels=['D', 'C', 'B', 'A']  # 分箱后分类的标签\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
